from fastapi import APIRouter, Depends, Query
from sqlalchemy.orm import Session
from typing import List

from app.db.database import get_db
from app.core.security import get_current_user, get_current_active_user
from app.schemas.post import PostBrief, PostWithDetails
from app.schemas.user import UserBrief
from app.schemas.campsite import CampsiteBrief
from app.services.recommendation import recommendation_service

router = APIRouter()


@router.get("/posts", response_model=List[PostWithDetails])
async def recommend_posts(
    limit: int = Query(20, ge=1, le=100),
    current_user: dict = Depends(get_current_active_user),
    db: Session = Depends(get_db)
):
    """为当前用户推荐帖子"""
    posts = recommendation_service.recommend_posts(db, user_id=current_user["id"], limit=limit)
    return posts


@router.get("/campsites", response_model=List[CampsiteBrief])
async def recommend_campsites(
    limit: int = Query(10, ge=1, le=50),
    current_user: dict = Depends(get_current_active_user),
    db: Session = Depends(get_db)
):
    """为当前用户推荐营地"""
    campsites = recommendation_service.recommend_campsites(db, user_id=current_user["id"], limit=limit)
    return campsites


@router.get("/users", response_model=List[UserBrief])
async def recommend_users(
    limit: int = Query(10, ge=1, le=50),
    current_user: dict = Depends(get_current_active_user),
    db: Session = Depends(get_db)
):
    """为当前用户推荐其他用户"""
    users = recommendation_service.recommend_users(db, user_id=current_user["id"], limit=limit)
    return users 